package com.theone.dagger2.use1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import com.theone.dagger2.R;
import com.theone.dagger2.bean.UserBean;

import javax.inject.Inject;


/**
 * TODO Dagger2 - 可以减低（程序中对象的）耦合度
 * UserBean 对象直接由 UserModule 提供
 *
 * 生成代码位置：build/generated/ap_generated_sources/debug/out/com/theone/dagger2
 */
public class MainActivity1 extends AppCompatActivity {

    @Inject
    UserBean mUser;
    @Inject
    UserBean mUser2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main1);
        // DaggerUserComponent.class 是生成的
        DaggerUserComponent.create().injectMainActivity(this);

        /*
            方法二
            DaggerUserComponent.builder()
                .userModule(new UserModule())
                .build()
                .injectMainActivity(this);
         */

        TextView textView = findViewById(R.id.textview);
        textView.setText("User hashCode = "+mUser.hashCode()+"\nUser2 hashCode = "+mUser2.hashCode());

    }

}